//
//  MRCityViewController.m
//  Travel_World
//
//  Created by dllo on 15/10/14.
//  Copyright © 2015年 TLS. All rights reserved.
//

#import "MRCityViewController.h"
#import "MRCountry_DiscountModel.h"
//#import "MRCityViewController.h"
#import "MRCityLocalDiscount_TableViewCell.h"
#import "MRCityNewDiscount_TableViewCell.h"
#import "MRScrollAndPageView.h"
#import "MRCountry_messageViewController.h"
#import "MRDiscount_ViewController.h"
#import "MRCountry_messageViewController.h"
#import "MRCityHotelViewController.h"
#import "SSCollectionModel.h"
#import "SSCollectionDataTool.h"
#import "TLS_countryModel.h"



@interface MRCityViewController ()<UITableViewDataSource,UITableViewDelegate>

@property (nonatomic, strong) NSMutableDictionary *dic;

@property (nonatomic, strong) UITableView *tableView;

@property (nonatomic, strong) NSMutableArray *local_discountArr;

@property (nonatomic, strong) NSMutableArray *discountArr;

@property (nonatomic, strong) UIView *headerView;

@property (nonatomic, strong) UIView *footerView;

//@property (nonatomic, strong) UITextField *inTextField;
//
//@property (nonatomic, strong) UITextField *outTextField;

@property (nonatomic, strong) UILabel *inLabel;

@property (nonatomic, strong) UILabel *outLabel;

@property (nonatomic, strong) UIDatePicker *datePicker;

@property (nonatomic, strong) UIView *dateView;

@property (nonatomic, strong) UIDatePicker *datePickerDown;

@property (nonatomic, strong) UIView *dateViewDown;

@property (nonatomic, strong) UIButton *collection;

@end

@implementation MRCityViewController

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
    self.tabBarController.tabBar.hidden = YES;
    
    self.navigationController.navigationBar.translucent = YES;
    //self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
    
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"bigShadow"] forBarMetrics:UIBarMetricsCompact];
    self.navigationController.navigationBar.layer.masksToBounds = YES;
    
    self.navigationController.navigationBar.translucent = YES;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self createTableView];
    
    [self createHeaderView];
    
    [self createFooterView];
    
    [self createData];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(localPush:) name:@"collectionViewClick" object:nil];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(discountPush:) name:@"tableViewClick" object:nil];
    
}

#pragma mark collectionView通知中心点击方法
- (void)localPush:(NSNotification *)notification
{
    MRCountry_messageViewController *messVC = [[MRCountry_messageViewController alloc] init];
    messVC.url = [NSString stringWithFormat:@"http://m.qyer.com/z/deal/%@/?source=app&client_id=qyer_ios&track_app_version=6.7&track_deviceid=41AE760B-510C-4778-AF4D-177B387E0F3B&track_user_id=6852801",notification.userInfo[@"index"]];
    
    [self.navigationController pushViewController:messVC animated:YES];
}

#pragma mark tableView通知中心点击方法
- (void)discountPush:(NSNotification *)notification
{
    
    MRCountry_messageViewController *messVC = [[MRCountry_messageViewController alloc] init];
    messVC.url = [NSString stringWithFormat:@"http://m.qyer.com/z/deal/%@/?source=app&client_id=qyer_ios&track_app_version=6.7&track_deviceid=41AE760B-510C-4778-AF4D-177B387E0F3B&track_user_id=6852801",notification.userInfo[@"index"]];
    
    [self.navigationController pushViewController:messVC animated:YES];
    
}

#pragma mark 数据解析
- (void)createData
{
    
    [QTAFNnetWorkTool getUrl:self.url body:nil hudSuperView:self.view result:QTJSON headerFile:nil success:^(id result) {
        
        self.dic = result[@"data"];
        
        self.local_discountArr = [MRCountry_DiscountModel baseModelByArr:result[@"data"][@"local_discount"]];
        
        self.discountArr = [MRCountry_DiscountModel baseModelByArr:result[@"data"][@"new_discount"]];
        
        [self createScrollView];
        
        [self.tableView reloadData];
        
//        NSLog(@"local_discount%@",self.local_discountArr);
        
    }];
    
}


#pragma mark 创建TableView
- (void)createTableView
{
    
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT + 64) style:UITableViewStyleGrouped];
    
    self.tableView.contentInset = UIEdgeInsetsMake(280 * HEI, 0, 0, 0);
    
    //    self.tableView.backgroundColor = [UIColor redColor];
    
    [self.view addSubview:self.tableView];
    
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    
//    self.tableView.rowHeight = 90 * HEI;
}

#pragma mark tableView的section个数
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // 判断精彩当地游和超值自由行数组都有数据的时候返回两个section,都不存在返回0个,其中一个存在数据,返回一个
    if (self.local_discountArr.count != 0 && self.discountArr.count != 0) {
        return 2;
    } else if (self.local_discountArr.count == 0 && self.discountArr.count == 0) {
        return 0;
    } else {
        return 1;
    }
    
}

#pragma mark tableView的cell的个数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (self.local_discountArr.count == 0 && self.discountArr.count == 0) {
        return 0;
    }
    return 1;
}

#pragma mark 创建tableView的cell
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    if (self.local_discountArr.count != 0 && self.discountArr.count != 0) {
        if (indexPath.section == 0) {
            
            static NSString *resueZero = @"zero";
            MRCityLocalDiscount_TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:resueZero];
            if (!cell) {
                cell = [[MRCityLocalDiscount_TableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:resueZero];
            }
            
            // 将解析后的数据传到cell的collectionView中
            cell.arr = self.local_discountArr;
            
            [cell.collectionView reloadData];
            
            return cell;
            
            
        } if (indexPath.section == 1) {
            
            static NSString *resueOne = @"one";
            MRCityNewDiscount_TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:resueOne];
            if (!cell) {
                cell = [[MRCityNewDiscount_TableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:resueOne];
            }
            
            
            // 将解析后的数据传到cell的tableView中
            cell.arr = self.discountArr;
            
            [cell.tableView reloadData];
            
            return cell;
            
        }
        
    } else if (self.local_discountArr.count == 0 && self.discountArr.count == 0) {
        
        return nil;
        
    } else {
        if (self.local_discountArr.count != 0) {
            
            static NSString *resueZero = @"zero";
            MRCityLocalDiscount_TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:resueZero];
            if (!cell) {
                cell = [[MRCityLocalDiscount_TableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:resueZero];
            }
            
            // 将解析后的数据传到cell的collectionView中
            cell.arr = self.local_discountArr;
            
            [cell.collectionView reloadData];
            
            return cell;
            
        } else if (self.discountArr.count != 0) {
            
            static NSString *resueOne = @"one";
            MRCityNewDiscount_TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:resueOne];
            if (!cell) {
                cell = [[MRCityNewDiscount_TableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:resueOne];
            }
            
            
            // 将解析后的数据传到cell的tableView中
            cell.arr = self.discountArr;
            
            [cell.tableView reloadData];
            
            return cell;
        }
        
    }
    return nil;
}

#pragma mark tableView的cell的行高
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    // 判断精彩当地游和超值自由行数组是否有数据
    if (self.local_discountArr.count != 0 && self.discountArr.count != 0) {
        
        if (indexPath.section == 0) {
            return 400 * HEI;
        } else if (indexPath.section == 1) {
            return self.discountArr.count * 90 * HEI;
        }
        
    } else if (self.local_discountArr.count == 0 && self.discountArr.count == 0) {
        return 0;
    } else {
        
        if (self.local_discountArr.count != 0 && self.discountArr.count == 0) {
            return 400 * HEI;
        } else if (self.discountArr.count != 0 && self.local_discountArr.count == 0) {
            return self.discountArr.count * 90 * HEI;
        }
    }
    return 0;
}

#pragma mark tableView的Header的文字
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    return @"fdsa";
}

#pragma mark tableView的Header
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(20 * WID, 0, WIDTH - 20 * WID, 60 * HEI)];
    view.backgroundColor = [UIColor whiteColor];
    
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(20, 10 * HEI, 150 * WID, 30 * HEI)];
//    label.textColor = [UIColor grayColor];
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
    button.frame = CGRectMake(260 * WID, 10 * HEI, 100 * WID, 30 * HEI);
    [button setFont:[UIFont systemFontOfSize:13]];
    [button setTintColor:[UIColor grayColor]];
    [button setTitle:@"查看全部 >" forState:UIControlStateNormal];
    
    
    if (self.local_discountArr.count != 0 && self.discountArr.count != 0) {
        if (section == 0) {
            
            label.text = @"精彩当地游";
            [view addSubview:label];
            
            [button addTarget:self action:@selector(localClick:) forControlEvents:UIControlEventTouchUpInside];
            [view addSubview:button];
            
        } if (section == 1) {
            
            label.text = @"超值自由行";
            [view addSubview:label];
            
            [button addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
            [view addSubview:button];
            
        }
        return view;
    } else if (self.local_discountArr.count == 0 && self.discountArr.count == 0) {
        return nil;
    } else {
        if (self.local_discountArr.count != 0 && self.discountArr.count == 0) {
            label.text = @"精彩当地游";
            [view addSubview:label];
            
            [button addTarget:self action:@selector(localClick:) forControlEvents:UIControlEventTouchUpInside];
            [view addSubview:button];
        } else if (self.discountArr.count != 0 && self.local_discountArr.count == 0) {
            label.text = @"超值自由行";
            
            [button addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
            [view addSubview:button];
        }
        return view;
    }
    return nil;
}

#pragma mark 精彩当地游button点击方法
- (void)localClick:(UIButton *)button
{
    MRDiscount_ViewController *mrVC = [[MRDiscount_ViewController alloc] init];
    NSString *url = [NSString stringWithFormat:@"http://open.qyer.com/qyer/discount/local_discount?client_id=qyer_ios&client_secret=cd254439208ab658ddf9&count=20&id=%@&lat=38.88257616485514&lon=121.5397588119696&oauth_token=55d7f8a1931dedc7d5a8f24ab63426d0&order=2&page=1&product_type=2410&time=1&track_app_channel=App%%2520Store&track_app_version=6.7&track_device_info=iPhone5%%2C4&track_deviceid=41AE760B-510C-4778-AF4D-177B387E0F3B&track_os=ios%%25209.0.2&track_user_id=6852801&type=2&v=1",self.dic[@"id"]];
    mrVC.content = self.dic[@"cnname"];
    mrVC.url = url;
    [self.navigationController pushViewController:mrVC animated:YES];
    
}

#pragma mark 超值自由行button点击方法
- (void)click:(UIButton *)button
{
    MRDiscount_ViewController *disVC = [[MRDiscount_ViewController alloc] init];
    NSString *url = [NSString stringWithFormat:@"http://open.qyer.com/qyer/discount/tickets_freewalker?client_id=qyer_ios&client_secret=cd254439208ab658ddf9&count=20&id=%@&lat=38.88257616485514&lon=121.5397588119696&oauth_token=55d7f8a1931dedc7d5a8f24ab63426d0&order=2&page=1&product_type=1016%%2C1018%%2C1020&time=1&track_app_channel=App%%2520Store&track_app_version=6.7&track_device_info=iPhone5%%2C4&track_deviceid=41AE760B-510C-4778-AF4D-177B387E0F3B&track_os=ios%%25209.0.2&track_user_id=6852801&type=2&v=1",self.dic[@"id"]];
    
    disVC.content = self.dic[@"cnname"];
    disVC.url = url;
    
    [self.navigationController pushViewController:disVC animated:YES];
}

- (void)createHeaderView
{
    self.headerView = [[UIView alloc]initWithFrame:CGRectMake(0, -280 * HEI, WIDTH, 280 * HEI)];
    self.headerView.backgroundColor = [UIColor whiteColor];
    [self.tableView addSubview:self.headerView];
}

- (void)createFooterView
{
    self.footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, 180 * HEI)];
//    self.footerView.backgroundColor = [UIColor yellowColor];
    self.footerView.backgroundColor = [UIColor groupTableViewBackgroundColor];
    self.tableView.tableFooterView = self.footerView;
    
    // 入住时间
    UILabel *inLabelFront = [[UILabel alloc] initWithFrame:CGRectMake(60 * WID, 30 * HEI, 100 * WID, 30 * HEI)];
    inLabelFront.text = @"入住时间:";
    [self.footerView addSubview:inLabelFront];
    
    self.inLabel = [[UILabel alloc] initWithFrame:CGRectMake(150 * WID, 30 * HEI, 120 * WID, 30 * HEI)];
    
//    self.inLabel.text = @"入住时间:";
//    self.inLabel.text = @"请选择时间...";
    self.inLabel.layer.borderWidth = 1;
    self.inLabel.layer.cornerRadius = 5;
    self.inLabel.textAlignment = NSTextAlignmentCenter;
    self.inLabel.textColor = [UIColor grayColor];
    [self.footerView addSubview:self.inLabel];
    
    UIButton *inButton = [UIButton buttonWithType:UIButtonTypeSystem];
    [inButton setImage:[UIImage imageNamed:@"iconfont-rili"] forState:UIControlStateNormal];
    inButton.frame = CGRectMake(270 * WID, 30 * HEI, 50 * WID, 30 * HEI);
    [inButton addTarget:self action:@selector(inLabelClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.footerView addSubview:inButton];
    
    // 离店时间
    UILabel *outLabelFront = [[UILabel alloc] initWithFrame:CGRectMake(60 * WID, 70 * HEI, 100 * WID, 30 * HEI)];
    outLabelFront.text = @"离店时间:";
    [self.footerView addSubview:outLabelFront];
    
    self.outLabel = [[UILabel alloc] initWithFrame:CGRectMake(150 * WID, 70 * HEI, 120 * WID, 30 * HEI)];
//    self.outLabel.text = @"离店时间:";
//    self.outLabel.text = @"请选择时间...";
    self.outLabel.layer.borderWidth = 1;
    self.outLabel.layer.cornerRadius = 5;
    self.outLabel.textAlignment = NSTextAlignmentCenter;
    self.outLabel.textColor = [UIColor grayColor];
    
    [self.footerView addSubview:self.outLabel];
    
    UIButton *outButton = [UIButton buttonWithType:UIButtonTypeSystem];
    [outButton setImage:[UIImage imageNamed:@"iconfont-rili"] forState:UIControlStateNormal];
    outButton.frame = CGRectMake(270 * WID, 70 * HEI, 50 * WID, 30 * HEI);
    [outButton addTarget:self action:@selector(outLabelClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.footerView addSubview:outButton];

    
    // 查询酒店
    UIButton *buttonHotel = [UIButton buttonWithType:UIButtonTypeSystem];
    buttonHotel.frame = CGRectMake(130 * WID, 110 * HEI, 115 * WID, 30 * HEI);
    [buttonHotel setTitle:@"查询酒店" forState:UIControlStateNormal];
    buttonHotel.layer.borderWidth = 1;
    buttonHotel.layer.cornerRadius = 10;
    [buttonHotel addTarget:self action:@selector(hotelPush:) forControlEvents:UIControlEventTouchUpInside];
    [buttonHotel setFont:[UIFont systemFontOfSize:20]];
    [self.footerView addSubview:buttonHotel];
    
}

#pragma mark 查询酒店
- (void)hotelPush:(UIButton *)button
{
    if (self.inLabel.text != nil && self.outLabel.text != nil) {
        
        MRCityHotelViewController *hotelVC = [[MRCityHotelViewController alloc] init];
        
        NSString *url = [NSString stringWithFormat:@"http://open.qyer.com/qyer/hotel/search_list?checkin=%@%2000%3A00%%3A01&checkout=%@%2023%3A59%%3A59&city_id=%@&client_id=qyer_ios&client_secret=cd254439208ab658ddf9&count=20&from_key=app_ios_city_search&lat=38.88261036070509&lon=121.5397574228773&oauth_token=55d7f8a1931dedc7d5a8f24ab63426d0&orderby=1&page=1&track_app_channel=App%%2520Store&track_app_version=6.7&track_device_info=iPhone5%%2C4&track_deviceid=41AE760B-510C-4778-AF4D-177B387E0F3B&track_os=ios%%25209.0.2&track_user_id=6852801&v=1",self.inLabel.text,self.outLabel.text,self.dic[@"id"]];
        
        hotelVC.url = url;
        hotelVC.content = self.dic[@"cnname"];
        
        hotelVC.Id = self.dic[@"id"];
        hotelVC.inLabelText = self.inLabel.text;
        hotelVC.outLabelText = self.outLabel.text;
        
        
        [self.navigationController pushViewController:hotelVC animated:YES];
        
    }
    
}

- (void)finishButton:(UIButton *)button
{

    NSDate *currDate = [self.datePicker date];
    // 得到当前的DatePicker的选中的时间
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    dateFormatter.dateFormat = @"YYYY-MM-dd";
    
    NSString *timeString = [dateFormatter stringFromDate:currDate];
    
    // 使用dateFormatter这种格式(短格式) 把currDate转化成字符串
    
    self.inLabel.textColor = [UIColor blackColor];
    self.inLabel.text = [NSString stringWithFormat:@"%@",timeString];
    
    [self.view sendSubviewToBack:self.dateView];
    
}

- (void)finishButton1:(UIButton *)button
{
    
    NSDate *currDate = [self.datePickerDown date];
    // 得到当前的DatePicker的选中的时间
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    dateFormatter.dateFormat = @"YYYY-MM-dd";
    
    NSString *timeString = [dateFormatter stringFromDate:currDate];
    
    // 使用dateFormatter这种格式(短格式) 把currDate转化成字符串
    self.outLabel.textColor = [UIColor blackColor];
    self.outLabel.text = [NSString stringWithFormat:@"%@",timeString];
    
    [self.view sendSubviewToBack:self.dateViewDown];
    
}

#pragma mark 入住时间点击方法
- (void)inLabelClick:(UIButton *)button
{
    
//    NSLog(@"inLabelClick");
    
//    [self.view bringSubviewToFront:self.dateView];
    
    NSDate *date = [NSDate date];
    
    self.dateView = [[UIView alloc] initWithFrame:CGRectMake(0, 150 * HEI, WIDTH, 300 * HEI)];
    self.dateView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.dateView];
//    [self.view sendSubviewToBack:self.dateView];
    
    self.datePicker = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, 50 * HEI, WIDTH, 200 * HEI)];
    self.datePicker.datePickerMode = UIDatePickerModeDate;
    NSLocale *locale = [[NSLocale alloc] initWithLocaleIdentifier:@"zh_CN"];
    self.datePicker.backgroundColor = [UIColor groupTableViewBackgroundColor];
    self.datePicker.locale = locale;
    [self.datePicker setDate:date animated:YES];
    [self.dateView addSubview:self.datePicker];
    
    
    UIButton *finish = [UIButton buttonWithType:UIButtonTypeSystem];
    finish.frame = CGRectMake(280 * WID, 30 * HEI, 70 * WID, 30 * HEI);
    [finish setTitle:@"完成" forState:UIControlStateNormal];
    [finish addTarget:self action:@selector(finishButton:) forControlEvents:UIControlEventTouchUpInside];
    [self.dateView addSubview:finish];
    
    
}

#pragma mark 离店时间点击方法
- (void)outLabelClick:(UIButton *)button
{
//    NSLog(@"outLabelClick");
    
//    [self.view bringSubviewToFront:self.dateViewDown];
    
    
    self.dateViewDown = [[UIView alloc] initWithFrame:CGRectMake(0, 150 * HEI, WIDTH, 300 * HEI)];
    self.dateViewDown.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.dateViewDown];
//    [self.view sendSubviewToBack:self.dateViewDown];
    
    NSDate *dateDown = [NSDate date];
    
    self.datePickerDown = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, 50 * HEI, WIDTH, 200 * HEI)];
    self.datePickerDown.backgroundColor = [UIColor groupTableViewBackgroundColor];
    self.datePickerDown.datePickerMode = UIDatePickerModeDate;
    NSLocale *locale1 = [[NSLocale alloc] initWithLocaleIdentifier:@"zh_CN"];
    self.datePickerDown.locale = locale1;
    [self.datePickerDown setDate:dateDown animated:YES];
    [self.dateViewDown addSubview:self.datePickerDown];
    
    UIButton *finish1 = [UIButton buttonWithType:UIButtonTypeSystem];
    finish1.frame = CGRectMake(280 * WID, 30 * HEI, 70 * WID, 30 * HEI);
    [finish1 setTitle:@"完成" forState:UIControlStateNormal];
    [finish1 addTarget:self action:@selector(finishButton1:) forControlEvents:UIControlEventTouchUpInside];
    [self.dateViewDown addSubview:finish1];
    
}

#pragma mark 创建轮播图
- (void)createScrollView
{
    
    NSMutableArray *picArr = [NSMutableArray array];
    
    [picArr addObjectsFromArray:self.dic[@"photos"]];
    
    MRScrollAndPageView *scrollView = [[MRScrollAndPageView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, 270 * HEI) Arr:picArr];
    
    //    scrollView.tag = 7;
    // 创建完collectionView之后记得将轮播图添加到collectionView上
    //    NSLog(@"scrollView 图片%ld",picArr.count);
    //    scrollView.backgroundColor = [UIColor blueColor];
    [self.headerView addSubview:scrollView];
    
    UILabel *cnname = [[UILabel alloc] initWithFrame:CGRectMake(40 * WID, 130 * HEI, 100 * WID, 40 * HEI)];
    cnname.text = self.dic[@"cnname"];
    cnname.textColor = [UIColor whiteColor];
    cnname.font = [UIFont systemFontOfSize:23];
    [self.headerView addSubview:cnname];
    
    UILabel *enname = [[UILabel alloc] initWithFrame:CGRectMake(40 * WID, 170 * HEI, 150 * WID, 20 * HEI)];
    enname.text = self.dic[@"enname"];
    enname.textColor = [UIColor whiteColor];
    enname.font = [UIFont systemFontOfSize:14];
    [self.headerView addSubview:enname];
    
    UILabel *content = [[UILabel alloc] initWithFrame:CGRectMake(40 * WID, 200 * HEI, 200 * WID, 50 * HEI)];
    content.text = self.dic[@"entryCont"];
    content.numberOfLines = 2;
    content.textColor = [UIColor whiteColor];
    content.font = [UIFont systemFontOfSize:14];
    [self.headerView addSubview:content];
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
    button.frame = CGRectMake(220 * WID, 230 * HEI, 150 * WID, 30 * HEI);
    [button setTintColor:[UIColor whiteColor]];
    [button setTitle:@"城市实用信息 >" forState:UIControlStateNormal];
    [button setFont:[UIFont systemFontOfSize:14]];
    [button addTarget:self action:@selector(buttonClick) forControlEvents:UIControlEventTouchUpInside];
    [self.headerView addSubview:button];
    
    
    TLS_cityModel *model = [[TLS_cityModel alloc] init];
    model.cnname = self.dic[@"cnname"];
    [[SSCollectionDataTool shareSSCollectionDataToolWithModelType:CityModel] createTabelWithModelType:CityModel];
    
    self.collection = [UIButton buttonWithType:UIButtonTypeSystem];
    self.collection.frame = CGRectMake(280 * WID, 135 * HEI, 40 * WID, 40 * HEI);
    [self.collection addTarget:self action:@selector(collection:) forControlEvents:UIControlEventTouchUpInside];
    [self.headerView addSubview:self.collection];
    
    
    if ([[SSCollectionDataTool shareSSCollectionDataToolWithModelType:CityModel] isIntable:model] == NotInTable) {
        
        [self.collection setImage:[UIImage imageNamed:@"iconfont-xihuan"] forState:UIControlStateNormal];
        
    } else {
        
        [self.collection setImage:[UIImage imageNamed:@"iconfont-xihuan(1)"] forState:UIControlStateNormal];
        
    }

    
    
}

#pragma mark 收藏方法
- (void)collection:(UIButton *)button
{
    TLS_cityModel *model = [[TLS_cityModel alloc] init];
    model.Id = self.dic[@"id"];
    model.cnname = self.dic[@"cnname"];
    model.enname = self.dic[@"enname"];
    model.photo = self.dic[@"photos"][0];
    
    SelectInTable result = [[SSCollectionDataTool shareSSCollectionDataToolWithModelType:CityModel] isIntable:model];
    
    if (result == InTable) {
        model.cnname = self.dic[@"cnname"];
        
        UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"警告" message:@"是否取消收藏?" preferredStyle:UIAlertControllerStyleAlert];
        UIAlertAction *leftAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
        UIAlertAction *rightAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
            
            [[SSCollectionDataTool shareSSCollectionDataToolWithModelType:CityModel] deleteCollectoinData:model modelType:CityModel];
            
            [self.collection setImage:[UIImage imageNamed:@"iconfont-xihuan"] forState:UIControlStateNormal];
            
        }];
        [alertController addAction:leftAction];
        [alertController addAction:rightAction];
        [self presentViewController:alertController animated:YES completion:nil];
        
    }else if(result == NotInTable) {
        
        UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"提示" message:@"是否收藏?" preferredStyle:UIAlertControllerStyleAlert];
        UIAlertAction *leftAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
        UIAlertAction *rightAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
            
            
            [[SSCollectionDataTool shareSSCollectionDataToolWithModelType:CityModel] inserCollectionData:model];
            
            [self.collection setImage:[UIImage imageNamed:@"iconfont-xihuan(1)"] forState:UIControlStateNormal];
            
        }];
        
        [alertController addAction:leftAction];
        [alertController addAction:rightAction];
        [self presentViewController:alertController animated:YES completion:nil];
    }else {
        
        NSLog(@"查询错误");
        
    }
    
}


#pragma mark 国家实用信息button的点击方法
- (void)buttonClick
{
    
    MRCountry_messageViewController *messVC = [[MRCountry_messageViewController alloc] init];
    messVC.url = self.dic[@"overview_url"];
    
    [self.navigationController pushViewController:messVC animated:YES];
    

    // Do any additional setup after loading the view.

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
